#include <string.h>

size_t strlen(const char *str) {
	size_t ret = 0;
	while (*str++)
		ret++;
	return ret;
}

void *memcpy(void *dest, const void *src, size_t n) {
	const char *sp = (const char *) src;
	char *dp = (char *) dest;
	
	for (; n != 0; n--)
		*dp++ = *sp++;

	return dest;
}

void *memset(void *addr, int value, size_t n) {
	char *addr2 = (char *) addr;
	char value2 = (char) value;
	
	while (n--)
		addr2[n] = value2;
	
	return addr;
}

char *strcpy(char *dest, const char *src) {
	char *tmp = dest;

	while (*src) {
		*dest = *src;
		dest++;
		src++;
	}
	
	return tmp;
}

char *strncpy(char *dest, const char *src, size_t n) {
	char *tmp = dest;
// :O
	while (*src && n) {
		*dest = *src;
		dest++;
		src++;
		n--;
	}
	
	return tmp;
}

int strcmp(const char *str1, const char *str2) {
	while (*str1 && *str2 && *str1 == *str2) {
		*str1++;
		*str2++;
	}
	 
	return *str1 - *str2;
}

char *strncat(char *dest, const char *src, size_t n) {
	size_t pos = strlen(dest);
	while (n && *src) {
		dest[pos] = *src;
		src++;
		pos++;
		n--;
	}
	return dest;
}
